using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace WindowsClient
{


    public class FloatingPanel : Panel
    {
        public event EventHandler Undocked;


        public FloatingPanel()
        {

        }


        public void InitializePanel()
        {

            Point location = PointToScreen(Point.Empty);
            // For more control, this would be a custom form.
            // You could then event handlers that would react when
            // it is dragged to an edge, and redock it automatically.
            floatForm = new Form();
            floatForm.StartPosition = FormStartPosition.CenterParent;
            floatForm.Owner = this.FindForm();
            Point pt = location;
            pt.Offset(5, 5);
            floatForm.Location = pt;
            floatForm.Text = this.Text;
            floatForm.FormBorderStyle = FormBorderStyle.SizableToolWindow;
            floatForm.ClientSize = this.Size;
            // A control can be contained in only one form. This moves
            // the ToolStrip out of the original form and into the floating form.
            floatForm.Controls.Add(this);
            floatForm.Show();
            // Raise the event to notify the form.
            if (Undocked != null) Undocked(this, EventArgs.Empty);
        }

        protected override void OnMouseDown(MouseEventArgs mea)
        {

            if (this.DisplayRectangle.Contains(mea.Location))
            {
                InitializePanel();
            }
            else
            {
                // Perform the normal mouse-click handling.
                base.OnMouseDown(mea);
            }
        }
        private Form floatForm;
        public Form FloatForm
        {
            get { return floatForm; }
        }
    }











}
